layui.use(['layer'], function(){
  var $ = layui.jquery,
  	layer = layui.layer;
  
  	$('#loginBtn').click(function(){
	  	var username = $('input[name=username]');
	  	var password = $('input[name=password]');
	  	var captcha = $('input[name=captcha]');
	  	
	  	if(username.val() == '') {
		  	layer.tips('用户名必须填写', username, {
			  	tips: [2, '#FF5722'],
			  	time: 4000
		  	});
		  	username.focus();
		  	return false;
	  	}
	  	
	  	if(password.val() == '') {
		  	layer.tips('密码必须填写', password, {
			  	tips: [2, '#FF5722'],
			  	time: 4000
		  	});
		  	password.focus();
		  	return false;
	  	}
	  	
	  	if(captcha.val() == '') {
		  	layer.tips('验证码必须填写', captcha, {
			  	tips: [1, '#FF5722'],
			  	time: 4000
		  	});
		  	captcha.focus();
		  	return false;
	  	}
	  	
	  	$.ajax({
	  		url: $('form').attr("action"),
	  		data: {
	  			username: username.val(),
	  			password: password.val(),
	  			captcha: captcha.val()
	  		},
	  		method: 'POST',
	  		type: 'JSON',
	  		success: function(res){
	  			if(res.code == 0){
	  				location.href = res.data;
	  			}else{
	  				layer.msg(res.msg,{icon: 5});
	  			}
	  		}
	  	});
  	});
});